Sanitize asset paths before passing them to the loader #223
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The bevy asset loader has a very unfortunate behavior of panicking if it receives an asset path with invalid syntax.
To prevent that I've changed the implementation of
AssetSource
from providingFrom<&AssetSource> for String
toTryFrom<&AssetSource> for String
, forcing us to verify that the asset source can be converted into an asset path with correct syntax before we pass it along to the bevy asset loader.There are some cases where we just want to get any string out of the asset source and don't need it to have valid syntax, so for that I created an unsafe
AssetSource
method that simply does what the String conversion used to do. But this forces us to useunsafe
and verify that we don't need valid syntax before using it.To A/B test the panicking behavior, you can simply load up the demo world, select anything with a texture (e.g. wall or floor) and type one colon
:
anywhere in the asset source path. On the currentmain
that will immediately make it panic. With this PR it should never panic; instead it will log an error to the console.